﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Text.RegularExpressions;

namespace DuoEr
{
    public partial class Main : Form
    {
        public Main()
        {
            InitializeComponent();
        }
        const string simg = @"<p><img style=""background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px"" src=""$1.png"" width=""660"">";
        private void btnFormat_Click(object sender, EventArgs e)
        {
            string input = tbInput.Text.Trim();
            input = Regex.Replace(input, @"<a href=""\$image_?.+?\.png"">(.+?)</a>", "$1");
            input = Regex.Replace(input, @"<a href=""\$image_?.+?\.jpg"">(.+?)</a>", "$1");
            input = Regex.Replace(input, @"<h6>(.*?)</h6>", @"<h6 style=""font-size: 14px; font-weight: bold"">$1</h6>");
            input = Regex.Replace(input, @"<p><img.+?src=""(.+?)_thumb\.png""[^>]+>", simg);
            input = Regex.Replace(input, @"<p>图([^<]+)", @"<p align=""center"">图$1");
            tbOutput.Text = input;
        }

        private void tbOutput_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.Control && e.KeyCode == Keys.C)
            {
                Clipboard.Clear();
                Clipboard.SetText(tbOutput.SelectedText);
            }
            else if (e.Control & e.KeyCode == Keys.A)
            {
                tbOutput.SelectAll();
            }
        }

        private void tbInput_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.Control && e.KeyCode == Keys.C)
            {
               Clipboard.Clear();
               Clipboard.SetText(tbInput.SelectedText);
            }
            else if (e.Control & e.KeyCode == Keys.A)
            {
                tbInput.SelectAll(); 
            }
        }

    }
}
